<template>
    <view class="educationitem item" v-if="objInfo.product.coursestitle">
        <view class="store flexb">
            <view class="store_name flexb" @click="toLink('store')"> 
                <image class="icon" :src="imgpath + 'store_icon.png?v=' + imgVersion" mode="aspectFit" > </image>
                <view class="txt">{{ objInfo.store.title || '暂无相关信息' }}</view>
            </view>
            <view class="order_state" >{{getState(objInfo)}}</view>
        </view>
        <view class="order-content" @click="toLink('order')">
            <view class="order-info flexbox">
                <view class="flexl order_detail flexbox">
                    <view class="pic loadingImg">
                        <image
                            :src="objInfo.product.litpic "
                            mode="aspectFill"
                        />
                    </view>
                    <view class="detail">
                        <view class="h4">{{ objInfo.product.coursestitle }}</view>
                        <view class="info">
                            <view class="p">{{ objInfo.product.classtitle }}</view>
                        </view>
                    </view>
                </view>
                <view class="flexr order_count">
                    <view class="p_pirce">{{globalData.appConfig && globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'}}{{ objInfo.orderprice }}</view>
                    <view class="p_count">x{{ objInfo.procount }}</view>
                    <view class="pstate" v-if="objInfo.orderstate == 8 || objInfo.orderstate == 9">{{ objInfo.orderstate == 8 ? '退款中' : '退款成功' }}</view>
                </view>
            </view>
            <view class="order-pay flexbox">
                <view>实付：</view><view class="pay_price">{{ globalData.appConfig && globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'  }}<view class="b">{{ (objInfo.orderprice.toString()).split('.')[0] }}<text v-if="(objInfo.orderprice.toString()).includes('.')">.{{ (objInfo.orderprice.toString()).split('.')[1] }}</text></view></view>
            </view>
        </view>
        <view class="orderBtns">
            <template v-if="objInfo.orderstate == '0'">
                <view class="btn cancel" @click="toLink('cancel')">取消订单</view>
                <!-- <view class="btn share"  @click="toLink('share')">找人付</view> -->
                <view class="btn pay" @click="toLink('pay')">去付款</view>
            </template>
            <template v-else-if="objInfo.orderstate == '1'">
                <view class="btn todetail" @click="toLink('order')">订单详情</view>
            </template>
            <template v-else-if="objInfo.orderstate == '2'">
                <!-- <view class="btn comment" @click="toLink('comment')">评价</view> -->
            </template>
            <template v-else-if="objInfo.orderstate == '7' || objInfo.orderstate == '9'">
                <view class="btn del" @click="toLink('del')">删除订单</view>
                <view class="btn rebuy" @click="toLink('rebuy')">重新报名</view>
            </template>
            <template v-else-if="objInfo.orderstate == '8'">
                <!-- <view class="btn cancel_tui"  @click="toLink('cancel')">取消退款</view>
                <view class="btn todetail" @click="toLink('order')">查看券码</view> -->
            </template>
        </view>
    </view>
</template>

<script>
    const app = getApp();
    export default{
        props:{
            objInfo:{
                type:Object,
                default:{
                    
                }
            },
            ind:{
                type:Number,
                default:0
            }
        },
        computed:{
            getState(){
                return function(order){
                    const that = this;
                    let orderstate = order.orderstate;
                    let stateText = '';
                    switch(orderstate){
                        case '0':
                            stateText = '待付款';
                            break;
                        case '1':
                            stateText = '已付款';
                            break;
                        case '3':
                            stateText = '交易成功';
                            break;
                        case '7':
                            stateText = '已取消';
                            break;
                        case '8':
                            stateText = '交易关闭';
                            break;
                        case '9':
                            stateText = '交易关闭';
                            break;
                    }
                    return stateText
                }
            },
        },
        data(){
            return {
                globalData:app.globalData,
                imgVersion:app.globalData.imgVersion,
                imgpath:app.globalData.imgPath + '/member/order/',
            }
        },
        mounted(){
        },

        methods:{
            // 点击页面跳转 
            /***
             * @param {*} type 跳转类型  order => 详情   
             */
            toLink(type){
                const that = this;
                let url = ''
                switch(type){
                    case 'pay':
                        uni.$emit('payorder',{objInfo:this.objInfo,ind:this.ind})
                        break;
                    case 'cancel':
                        uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind})
                        break;
                    case 'order':
                        url = `${app.globalData.appConfig && app.globalData.appConfig.cfg_user_index }/orderdetail-education-${order.id}.html`
                        app.linkTo(url,false,false)
                        break;
                    case 'store':
                        url = order.store.url;
                        app.linkTo(url,false,false)
                        break;
                    case 'rebuy':
                        url = order.product.url.replace('class-detail','comfirm')
                        app.linkTo(url,false,false)
                        break;
                    case 'del':
                        url = `${app.globalData.appConfig && app.globalData.appConfig.cfg_user_index }/orderdetail-education-${order.id}.html`
                        uni.$emit('delorder',{objInfo:this.objInfo,ind:this.ind})
                        break;
                }
            }
        }
    }
</script>

<style scoped>
     @import './orderlist_education.css'
</style>